package day16;

public class Protect implements Runnable {
    public void run() {
        while (true) {
            try {
                Thread.sleep(1000);
                System.out.println("I am protected");
            } catch (InterruptedException e) {
                System.out.println("中断");
                throw new RuntimeException(e);
            }
        }
    }
}

class User implements Runnable {
    public void run() {
        for (int i = 0; i < 10; i++) {
            try {
                Thread.sleep(1000);
                System.out.println("用户线程执行");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }

    public static void main(String[] args) {
        Protect pro = new Protect();
        User user = new User();
        Thread t1 = new Thread(pro);
        t1.setDaemon(true);
        Thread t2 = new Thread(user);
        t1.start();
        t2.start();
    }
}
